package com.Algorithm.Test;

import com.TempletGenerate.IntNumGenerate;

import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/10/22/10:53
 * @Description:
 * @Target: 判断是升序还是降序?
 */
public class IsSortTest {

    public static void main(String[] args) {
        int[] ints = {1, 2, 3, 4, 5, 6};
        int[] ints1 = {6,5,4,3,2,1};

        IntNumGenerate intNumGenerate = new IntNumGenerate();
        int[] ints2 = intNumGenerate.RandomInt(10, 1, 9);
        for (int anInt : ints2) {
            System.out.print(anInt+" ");
        }
        System.out.println();

        IsSortSum(ints);
        IsSortSum(ints1);
        IsSortSum(ints2);

    }

    public static void IsSortSum(int arr[]){
        if (arr[0]<arr[arr.length-1]){  // 弄第一个最后一个是为了防止长度为1...
            System.out.println("升序?"+IsSort(arr));
        }else {
            System.out.println("降序?"+IsDescSort(arr));
        }
    }

    public static boolean IsDescSort(int arr[]){
        boolean flag = false;
        int i=0;
        int j=1;
        if (arr.length<1){
            flag = true;
        }

        while (j<arr.length){
            if (arr[i++]>=arr[j++]){
                flag = true;
            }else {
                flag = false;
                break;
            }
        }

       return flag;
    }




    public static boolean IsSort(int arr[]){
        boolean flag = false;

        int i=0;
        int j=1;
        if (arr.length<1){
            flag = true;
        }



        while (j<arr.length){
            if (arr[i++]<=arr[j++]){
                flag = true;
            }else {
                flag = false;
                break;
            }

        }

        return flag;
    }


}

